#include "String.h"

class Solution {
public:
    string reverseWords(string s) {

        if (s.empty()) return s;
        int l = 0, r = 0, len = s.size();

        while (r < len)
        {
            while (r < len && s[r] != ' ') r++;
            reverse(s.begin() + l, s.begin() + r);
            l = r + 1;
            r++;
        }
        reverse(s.begin() + l, s.begin() + r);
        return s;
    }
};